import time
import os
from multiprocessing.managers import BaseManager
import thread

class MathsClass(object):
    def __init__(self,extra):
        self.extra = extra

    def add(self, x, y):
        print self.extra
        print 'pid',os.getpid(), ' threadid',thread.get_ident()
        time.sleep(2)
        return x + y
    def mul(self, x, y):
        print self.extra
        print 'pid',os.getpid(), ' threadid',thread.get_ident()
        return x * y 


class MathManager(BaseManager): pass
# MathManager.register('math', callable=lambda:MathsClass())
test=MathsClass('extra message')

MathManager.register('math', callable=lambda:test)
m = MathManager(address=('', 50000), authkey='abc')
m.start()

while True:
    print 'mangaer server start obj: {}  pid={}'.format(test,os.getpid())
    time.sleep(5)
    print 'shutdown ...',m.shutdown()